
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { ApiService } from 'src/app/core/api';
import { StorageService } from '../sotrage/storage.service';

@Injectable()
export class SmrzActivate implements Resolve<any> {
	constructor(private apiService: ApiService, private sto: StorageService) { }
	resolve() {
		let user = this.sto.get('user');
		return this.apiService.post('用户详情', { mobile: user['mobile'] }).then(res => {
			localStorage.setItem('userMap', JSON.stringify(res['data']['whiteHatUserDetail']));
			return res['data'];
		}).catch(res => {
			return res;
		});
	}
}
/**
 * 项目详情-路由守卫
 */
@Injectable()
export class ProjectDetailActivate implements Resolve<any> {
	constructor(private apiService: ApiService, private sto: StorageService) { }
	resolve(route: ActivatedRouteSnapshot) {
		// let user = this.sto.get('user');
		// const id = route.queryParams['id'];
		// const s = route.queryParams['s'] == '人数已满' ? true : false;
		// let url = user?'项目详情':'项目详情(未登录)';
		// return this.apiService.post(url, { id: id }).then(res => {
		// 	let data = res['data'];
		// 	data.isUser = user?true:false;
		// 	data.s = s;
		// 	return data;
		// }).catch(res => {
		// 	return res;
		// });
	}
}
/**
 * 我的漏洞首页-路由守卫
 */
@Injectable()
export class MyBugsActivate implements Resolve<any> {
	constructor(private apiService: ApiService, private sto: StorageService) { }
	resolve() {
		return this.apiService.post('我的漏洞列表', { pageNo: 1,status:"",belongProject:'',beginTime:'',endTime:'' }).then(res => {
			let data = res['data'];
			return data;
		}).catch(res => {
			return res;
		});
	}
}
/**
 * 我的漏洞首页-路由守卫
 */
@Injectable()
export class BugDetailActivate implements Resolve<any> {
	constructor(private apiService: ApiService, private sto: StorageService) { }
	resolve(route: ActivatedRouteSnapshot) {
		const id = route.queryParams['id'];
		console.log(id);
		return this.apiService.post('漏洞详情', {id}).then((res: any) => {
            return res['data']['bugDetail'];
        }).catch((res) => {
			return res;
        });
	}
}
